package validate;

import java.util.regex.Pattern;

public class RegexValidator extends AbstractValidator
{
	private Pattern pattern;
	
	private String errorMessage;
	
	public RegexValidator(String regex, String errorMessage)
	{
		pattern = Pattern.compile(regex);
		
		this.errorMessage = errorMessage;
	}
	
	@Override
	public boolean validate(String input)
	{
		return input != null && pattern.matcher(input).matches();
	}
	
	@Override
	public String getErrorMessage()
	{
		return errorMessage;
	}
}
